"""
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    created by lane.chang on '21/08/2023'
    comment: 助手知识库连接
"""
import ujson
import asyncio
import aiohttp

from config import Config
from project.core.log import Colors
from project.lib.common import logger


class Radar:
    """
    """

    @staticmethod
    async def get_room_list(dev_id):
        """ 得到房间列表
        :return:
        """
        headers = {
            'Content-Type': 'application/json',
            'deviceId': dev_id
        }

        async with aiohttp.ClientSession() as session:
            async with session.post(f'{Config.RADAR_SERVER}/open/mmwRader/queryHeadCountByArea', headers=headers) as resp:
                response = await resp.json()
                logger.info(f'雷达信息: \n  {ujson.dumps(response, ensure_ascii=False, indent=4)}', font_color=Colors.PURPLE.value)

        # 加工结果
        result = [
            {
                'room_type': v['dataLabel'],
                'building_name': v['buildingName'],
                'floor_name': v['floorName'],
                'room_name': v['roomName'],
                # 'area_location': v['areaLocation'],
                'head_count': v['headCount']
            }
            for v in response.get('result', [])
        ]

        return result


if __name__ == "__main__":
    result = asyncio.run(Radar.get_room_list())

    print(result)
